// SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
// SPDX-License-Identifier: Mulan PSL v2
package com.geniusai.aip.auth.constants;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.time.DateUtils;

import java.util.Date;

/**
 * @author lingchuanzhou19320
 * @date 2022/6/8
 */
@AllArgsConstructor
@Getter
public enum TrendChartTimeStepEnum {
    LAST_SEVEN_DAY("lastSevenDays", "近7天", "60"),
    LAST_THREE_DAY("lastThreeDays", "近3天", "25"),
    LAST_ONE_DAY("lastOneDays", "近1天", "300"),  // 20
    LAST_THREE_HOURS("lastThreeHours", "近3小时", "120"),  // 15
    LAST_ONE_HOURS("lastOneHours", "近1小时", "60");  // 5

     private String timeCode;
     private String timeDesc;
     private String timeStep;

    /**
     * 获取近n天/小时前时间戳
     * @param timeCode
     * @return
     */
     public static long getStartTimeStamp(String timeCode) {
         if(timeCode.equals(LAST_SEVEN_DAY.timeCode)) {
             return DateUtils.addDays(new Date(), -7).getTime() / 1000;
         }
         if(timeCode.equals(LAST_THREE_DAY.timeCode)) {
             return DateUtils.addDays(new Date(), -3).getTime() / 1000;
         }
         if(timeCode.equals(LAST_ONE_DAY.timeCode)) {
             return DateUtils.addDays(new Date(), -1).getTime() / 1000;
         }
         if(timeCode.equals(LAST_THREE_HOURS.timeCode)) {
             return DateUtils.addHours(new Date(), -3).getTime() / 1000;
         }
         if(timeCode.equals(LAST_ONE_HOURS.timeCode)) {
             return DateUtils.addHours(new Date(), -1).getTime() / 1000;
         }
         return 0;
     }

     public static String getTimeStep(String timeCode) {
         if(timeCode.equals(LAST_SEVEN_DAY.timeCode)) {
             return LAST_SEVEN_DAY.timeStep;
         }
         if(timeCode.equals(LAST_THREE_DAY.timeCode)) {
             return LAST_THREE_DAY.timeStep;
         }
         if(timeCode.equals(LAST_ONE_DAY.timeCode)) {
             return LAST_ONE_DAY.timeStep;
         }
         if(timeCode.equals(LAST_THREE_HOURS.timeCode)) {
             return LAST_THREE_HOURS.timeStep;
         }
         if(timeCode.equals(LAST_ONE_HOURS.timeCode)) {
             return LAST_ONE_HOURS.timeStep;
         }
         return "";
     }
}
